//
//  File.swift
//
//
//  Created by didi on 2022/9/13.
//

import MolecularObjects
import Vapor

public struct SystemVariableApi {
    let repository: SystemVariableRepository

    init(_ repository: SystemVariableRepository) {
        self.repository = repository
    }
}

public extension SystemVariableApi {
    func list() async throws -> [Variable.List] {
        try await repository.list().transform(to: [Variable.List].self)
    }

    func list(_ ids: [UUID]) async throws -> [Variable.List] {
        try await repository.get(ids).transform(to: [Variable.List].self)
    }

    func get(_ id: UUID) async throws -> Variable.Detail? {
        try await repository.get(id).transform(to: Variable.Detail.self)
    }

    func get(_ ids: [UUID]) async throws -> [Variable.Detail] {
        try await repository.get(ids).transform(to: [Variable.Detail].self)
    }

    func find(_ key: String) async throws -> Variable.Detail? {
        try await repository.find(key).transform(to: Variable.Detail.self)
    }
}
